package util;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
public class R implements Serializable {
    private String message;
    private int code;
    private  boolean flag;
    private Map<String,Object> data=new HashMap<>();


    private  R(){};

    public static  R ok(){
        R r = new R();
        r.message="操作成功";
        r.code=2000;
        r.flag=true;
        return  r;
    }
    public static  R error(){
        R r = new R();
        r.message="操作失败";
        r.code=2001;
        r.flag=false;
        return  r;
    }

    public R message(String message) {
        this.message = message;
        return this;
    }

    public R code(int code) {
        this.code = code;
        return this;
    }

    public R flag(boolean flag) {
        this.flag = flag;
        return this;
    }

    public R data(Map<String, Object> map) {
        this.data.putAll(map);
        return this;
    }
    public R data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
}
